package com.barneyx.mshinfoplatform.config.mybatisplus;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.barneyx.mshinfoplatform.exception.MshException;
import com.barneyx.mshinfoplatform.util.AreaUtil;
import lombok.AllArgsConstructor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class AreaSelectMethod extends AbstractMethod {
    @Resource
    private AreaUtil areaUtil;
    private static String methodName = "areaSelectMethod";

    /**
     * @param methodName 方法名
     * @since 3.5.0
     */
    protected AreaSelectMethod() {
        super(methodName);
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String sql = "select * from " + tableInfo.getTableName() + " where " + tableInfo.getKeyColumn() + "=#{" + tableInfo.getKeyProperty() + "}";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return addSelectMappedStatementForTable(mapperClass, methodName, sqlSource, tableInfo);
    }
}
